﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace MonitorAgent
{
   class SystemInfo
   {
      static PerformanceCounter cpuCounter;
      static PerformanceCounter ramCounter;

      public SystemInfo()
      {
         cpuCounter = new PerformanceCounter();

         cpuCounter.CategoryName = "Processor";
         cpuCounter.CounterName = "% Processor Time";
         cpuCounter.InstanceName = "_Total";

         ramCounter = new PerformanceCounter("Memory", "Available MBytes");
      }


      static public string getCurrentCpuUsage()
      {
         return cpuCounter.NextValue() + "%";
      }

      static public string getAvailableRAM()
      {
         return ramCounter.NextValue() + "MB";
      }

      static public string getUpTime()
      {
         TimeSpan ts = TimeSpan.FromMilliseconds(Environment.TickCount);

         return string.Format("{0}d {1}h {2}m {3}s", ts.Days, ts.Hours, ts.Minutes, ts.Seconds);
      }
   }
}
